home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CDICTION
/
CSMARTWI.C
< prev
next >
Wrap
Text File
|
1990-01-08
|
6KB
|
227 lines
/*****************************************************************************
CSmartWindow.c
see header for more information
SUPERCLASS = CWindow
*****************************************************************************/
#include "CSmartWindow.h"
#include "TBUtilities.h"
#include "TaoUtils.h"
#include "CSmartBartender.h"
#include "CTextEnvirons.h"
#include "Color.h"
#include "OSChecks.h"
#include "ColorToolbox.h"
#include "CDesktop.h"
#include "CDirector.h"
typedef struct WINDtemplate { /* Format of a WIND resource */
Rect boundsRect;
short WDEFid;
short visible;
short goAwayFlag;
long refCon;
Str255 title;
} WINDtemplate, *WINDtemplateP, **WINDtemplateH;
extern CSmartBartender *gBartender;
/*****************************************************************************/
void CSmartWindow::ISmartWindow(Int16 WINDid, Boolean aFloating,
CView *anEnclosure, CBureaucrat *aSupervisor,
Boolean sizeIsMax)
{
TextInfoRec textInfo;
WINDtemplateH theWIND;
Rect r;
CWindow::IWindow( WINDid, aFloating, (CDesktop*)anEnclosure, (CDirector*) aSupervisor);
itsEnvirons = new( CTextEnvirons);
itsEnvirons->ITextEnvirons();
textInfo.fontNumber = GetPreferredFontNum();
textInfo.theSize = 12;
textInfo.theStyle = 0;
textInfo.theMode = srcOr;
itsEnvirons->SetTextInfo( &textInfo);
/* if size is max we set up sizeRect so the WIND resource size
is our maximum size */
if (sizeIsMax)
{
theWIND = (WINDtemplateH) GetResource('WIND', WINDid);
r = (**theWIND).boundsRect;
sizeRect.right = r.right - r.left;
sizeRect.bottom = r.bottom - r.top;
SetStdState( &r);
HPurge( theWIND);
}
} /* CSmartWindow::ISmartWindow */
/*****************************************************************************/
void CSmartWindow::MakeMacWindow(Int16 WINDid)
{
PaletteHandle palH;
if (ColorQDIsPresent())
{
macPort = GetNewCWindow(WINDid, NULL,
(floating ? (WindowPtr)(-1L) : NULL));
palH = GetPalette( macPort);
if (!palH) /* no palette for this window, use the default */
{
palH = GetNewPalette( 0);
if (palH) SetPalette( macPort, palH, TRUE);
}
}
else
macPort = GetNewWindow(WINDid, NULL,
(floating ? (WindowPtr)(-1L) : NULL));
} /* CSmartWindow::MakeMacWindow */
/*****************************************************************************/
void CSmartWindow::RestoreEnvirons( void)
{
itsEnvirons->Restore();
} /* CSmartWindow::RestoreEnvirons */
/*****************************************************************************/
void CSmartWindow::Prepare( void)
{
inherited::Prepare();
itsEnvirons->Restore();
} /* CSmartWindow::Prepare */
/*****************************************************************************/
void CSmartWindow::SetFontNumber(Int16 aFontNumber)
{
TextInfoRec textInfo;
WindowPtr savedPort;
itsEnvirons->GetTextInfo( &textInfo);
textInfo.fontNumber = aFontNumber;
itsEnvirons->SetTextInfo( &textInfo);
GetPort( &savedPort);
SetPort( macPort);
TextFont( aFontNumber);
SetPort( savedPort);
} /* CSmartWindow::SetFontNumber */
/*****************************************************************************/
void CSmartWindow::SetFontName(Str255 aFontName)
{
Int16 fontNum; /* Corresponding font number */
/* Call utility to look up number for */
/* this font */
GetFontNumber(aFontName, &fontNum);
if (fontNum >= 0) { /* Legal font numbers are positive */
SetFontNumber(fontNum);
}
} /* CSmartWindow::SetFontName */
/*****************************************************************************/
void CSmartWindow::SetFontStyle(Int16 aStyle)
{
TextInfoRec textInfo;
WindowPtr savedPort;
itsEnvirons->GetTextInfo( &textInfo);
textInfo.theStyle = aStyle;
itsEnvirons->SetTextInfo( &textInfo);
GetPort( &savedPort);
SetPort( macPort);
TextFace( aStyle);
SetPort( savedPort);
} /* CSmartWindow::SetFontStyle */
/*****************************************************************************/
void CSmartWindow::SetFontSize(Int16 aSize)
{
TextInfoRec textInfo;
WindowPtr savedPort;
itsEnvirons->GetTextInfo( &textInfo);
textInfo.theSize = aSize;
itsEnvirons->SetTextInfo( &textInfo);
GetPort( &savedPort);
SetPort( macPort);
TextSize( aSize);
SetPort( savedPort);
} /* CSmartWindow::SetFontSize */
/*****************************************************************************/
void CSmartWindow::SetTextMode(Int16 aMode)
{
TextInfoRec textInfo;
WindowPtr savedPort;
itsEnvirons->GetTextInfo( &textInfo);
textInfo.theMode = aMode;
itsEnvirons->SetTextInfo( &textInfo);
GetPort( &savedPort);
SetPort( macPort);
TextMode( aMode);
SetPort( savedPort);
} /* CSmartWindow::SetTextMode */
/*****************************************************************************/
void CSmartWindow::ChangeSize(Int16 width, Int16 height)
{
Int16 currWidth, currHeight;
currWidth = macPort->portRect.right - macPort->portRect.left;
currHeight = macPort->portRect.bottom - macPort->portRect.top;
if ((currWidth == width) && (currHeight == height)) return;
inherited::ChangeSize( MIN( width, sizeRect.right),
MIN( height, sizeRect.bottom));
} /* CSmartWindow::ChangeSize */
/*****************************************************************************/
void CSmartWindow::BeModal( void)
{
if (!isModal)
{
isModal = TRUE;
Select(); /* make sure we're in front */
gBartender->DisableAllMenus(); /* disable the menu bar */
}
} /* CSmartWindow::BeModal */
/*****************************************************************************/
void CSmartWindow::ReleaseMode( void)
{
if (isModal)
{
isModal = FALSE;
gBartender->EnableAllMenus();
}
} /* CSmartWindow::ReleaseMode */
/*****************************************************************************/
Boolean CSmartWindow::IsModal( void)
{
return isModal;
} /* CSmartWindow::IsModal */
/*****************************************************************************/
void CSmartWindow::Dispose( void)
{
if (itsEnvirons) itsEnvirons->Dispose();
inherited::Dispose();
} /* CSmartWindow::Dispose */
/*****************************************************************************/